import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/home"
  },
  {
    path:"/login",
    name:"login",
    component:()=>import("../page/login.vue"),
  },
  {
    path:"/home",
    name:"home",
    component:()=>import("../views/About.vue"),
    children:[
      {
        path:"/home",
        redirect:"/home/page"
      },
      {
        path:"/home/page",
        name:"page",
        component:()=>import("../page/page.vue")
      },
      {
        path:"/home/class",
        name:"class",
        component:()=>import("../page/class.vue")
      },
      {
        path:"/home/shop",
        name:"shop",
        component:()=>import("../page/shop.vue")
      },
      {
        path:"/home/my",
        name:"my",
        component:()=>import("../page/my.vue"),
        beforeEnter: (to, from,next) => {
          let token=window.localStorage.getItem("token")
          if(!token){
            next("/login")
          }else{
            next()
          }
        },
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
